package com.fzy.core;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.ContextLoaderServlet;

public class MyContextLoaderServlet extends ContextLoaderServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final Log log = LogFactory
			.getLog(MyContextLoaderServlet.class);

	public static final String CLASS_MAPPINGS = "_mappings";

	public void init() throws ServletException {
		super.init();
		setupContext(getServletContext());
	}

	public static void setupContext(ServletContext context) {
		Map classMappings = new MappingBuilder()
				.beginClass("auth", "com.fzy.auth.entity.User", "用户", "fz_user", "用户")
				.id().status().record()
				.property("name", "登录名", "name", "登录名称", true, false)
				.property("password", "密码", "password", "登录密码", true, false)
				.property("nickname", "昵称", "nick_name", "显示名称", true, false)
				.endClass()
				.end();

		context.setAttribute(CLASS_MAPPINGS, classMappings);

		log.info("<=========== String context initialization is completed.");

	}
}
